// import JSEncrypt from 'jsencrypt'

// export default {
// encodeRSA(word, keyStr) {
// 这个是公钥,有入参时用入参，没有入参用默认公钥
const keyStr = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApZVseR/ZzUW73cB30h9y7mjLjvnuZ96G5OyJqfR5qNgt/hX3o6VwIapR/zsVtBMMpBkLyh8Jx9nGjOR/HXuvvYIuq93WexmbXTGyiZ6Ww1nb8QfmgDD9Tr46ev6tduxmnlp7t9Ff2XnUZN6xyJXngJVjzCboxHeubuDugnWKSwuZf4oNkDGCJHP9ELgGmQ1sJZuVSHQcDaJ+yFeZ7xX2x9RDEcVjrwE97xcB/SQl1QTZ08OEPZ1AcY51lx5pWWt9bLDjcczfmXPI3NFQPjaTI31kVGTO+4s+Jqi/Fxfa1EfRQpOxClbHwswri5d96Q5VWYHKZE99XiKnLJRZwZmxmQIDAQAB'
// keyStr = keyStr || 'Xlllllll'
// 创建对象
//     const jsRsa = new JSEncrypt()
//     // 设置公钥
//     jsRsa.setPublicKey(keyStr)
//     // 返回加密后结果
//     return jsRsa.encrypt(word)
//   }

// }
const privateKey = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCllWx5H9nNRbvdwHfSH3LuaMuO+e5n3obk7Imp9Hmo2C3+FfejpXAhqlH/OxW0EwykGQvKHwnH2caM5H8de6+9gi6r3dZ7GZtdMbKJnpbDWdvxB+aAMP1Ovjp6/q127GaeWnu30V/ZedRk3rHIleeAlWPMJujEd65u4O6CdYpLC5l/ig2QMYIkc/0QuAaZDWwlm5VIdBwNon7IV5nvFfbH1EMRxWOvAT3vFwH9JCXVBNnTw4Q9nUBxjnWXHmlZa31ssONxzN+Zc8jc0VA+NpMjfWRUZM77iz4mqL8XF9rUR9FCk7EKVsfCzCuLl33pDlVZgcpkT31eIqcslFnBmbGZAgMBAAECggEAGGWDrfT7ajs0CuAox1TK4kWeeFpqvfMTfPc88UWMB0ySujUSX5Ioi01E944F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882M0+6dbFCFCOHwLCXH6UV6JEjCe2Mb/Gh2RSShJFEfmFulomYsI3H4K7lGpL3Kta2XSg2lUDy97aDjy0Daf6A='

// @ts-ignore
import { JSEncrypt } from 'jsencrypt'

/**
 * RSA非对称加密
 * @param data 需要加密的数据
 */
export function rsaEncrypt(data) {
  // 公钥,，复制前面生成的公钥
  const PUBLIC_KEY = keyStr
  // 使用公钥加密
  const encrypt = new JSEncrypt()
  encrypt.setKey(PUBLIC_KEY)
  const result = encrypt.encryptUnicodeLong(encodeURIComponent(JSON.stringify(data)))
  return result
}

/**
 * RSA 解密
 * @param data 需要解密的数据
 */
export function rsaDecrypt(data) {
  // 私钥，复制对应的私钥用于解密
  const PRIVATE_KEY = privateKey // 使用私钥解密
  const decrypt = new JSEncrypt()
  decrypt.setKey(PRIVATE_KEY)
  // const result = JSON.parse(decrypt.decryptUnicodeLong(data))
  // const result = JSON.parse(decodeURIComponent(decrypt.decryptUnicodeLong(data)))
  const result = JSON.parse(decodeURIComponent(decrypt.decryptUnicodeLong(data)))
  return result
}

// 解密 decryptUnicodeLong
// 加密 encryptUnicodeLong
